package gui

import (
	"image/color"
	"wxp2p/clientN"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/data/binding"
	"fyne.io/fyne/v2/theme"
	"fyne.io/fyne/v2/widget"
)

var fileClient *clientN.ClientClient

func fileTransWindow(gVars *GlobalVars) fyne.CanvasObject {

	// 控制主机
	remoteClientId := binding.NewString()
	remoteClientIdEntry := widget.NewEntryWithData(remoteClientId)

	linkBtn := widget.NewButtonWithIcon("连接", theme.LoginIcon(), func() {
		clientId, _ := remoteClientId.Get()
		if fileClient != nil {
			fileClient.ClientId = clientId
			fileClient.StopRun()
		} else {
			fileClient = clientN.NewClientClient(gVars.signalAddr, remoteClientIdEntry.Text)
		}
		fileClient.ServerAddr = gVars.signalAddr
		fileClient.Run()
	})
	unlinkBtn := widget.NewButtonWithIcon("断开", theme.LogoutIcon(), func() {
		if fileClient != nil {
			fileClient.ClientId = remoteClientIdEntry.Text
			fileClient.StopRun()
		}
	})

	idRow := container.NewBorder(nil, nil, canvas.NewText("远程主机", nil), container.NewHBox(linkBtn, unlinkBtn), remoteClientIdEntry)
	fileRow := container.NewBorder(nil, nil, canvas.NewText("传输文件", nil), widget.NewButton("传输", func() {}), widget.NewEntry())

	panel := container.NewVBox(canvas.NewText("功能尚未实现", color.RGBA{R: 255}), idRow, fileRow)
	return panel
}
